package model

import (
    "fcs-api/src/client"
    "time"

    "git.inspur.com/x/common/loggerfactory"
    "git.inspur.com/x/keycloak"
    "github.com/minio/minio-go/v7"
)

var logger = loggerfactory.GetLogger()

var Base BaseInfo

type ListenInfo struct {
    Name      string
    Namespace string
    ReadyChan chan bool
    StartTime time.Time
}

type BaseInfo struct {
    KnativeClusterUser       string
    KnativeClusterPwd        string
    ContainerImageRegistry   string
    CirEndpoint              string // 容器镜像服务地址
    RuntimeImage             RuntimeImage
    BssMqInfo                BssMqInfo
    IamApiServerHost         string
    FunctionInvokeHost       string
    HttpInvokeHost           string
    GatewayNamespace         string
    OssDownloadHost          string
    OssAdminHost             string
    OssUserHost              string
    OssEndpoint              string
    OssBucket                string
    OssAK                    string
    OssSK                    string
    ApigHost                 string
    KsvcWaitingTime          int
    ESHost                   string
    LogDelayTime             int
    CallbackUser             string
    CallbackEndpoint         string
    NetworkpolicyWhitelistIp string
    FunctionBlockCidr        string
    VpcHost                  string
    EipHost                  string
    IceHost                  string
    EcsHost                  string
    ClusterMasterIp          string
    ClusterMasterPwd         string
    KeycloakConfig           *keycloak.Config
    KeycloakClient           keycloak.Interface
    InfluxdbHost             string
    InfluxdbUser             string
    InfluxdbP6d              string
    Region                   string
    Cluster                  string
    MinioClient              *minio.Client
    CecURL                   string
    FreeCount                int64   // 每月调用免费额度，单位万次
    FreeComputePower         float64 // 每月调用免费算力，单位gb/s
    ClusterManager           client.ClusterClientManager
    AdminToken               string          // 管理员账户的token
    CloudType                string          // region类型 public 公有云 native 政务云
    Queue                    chan ListenInfo // 函数监听队列
}

type BssMqInfo struct {
    Url                    string
    Exchange               string
    OrderQueue             string
    OrderRouteKey          string
    OrderCallbackQueue     string
    OrderCallbackRouteKey  string
    ChangeQueue            string
    ChangeRouteKey         string
    ChangeCallbackQueue    string
    ChangeCallbackRouteKey string
    BillQueue              string
    BillRouteKey           string
    MessageTTL             int
    DeadLetterExchange     string
    DeadLetterRouteKey     string
}

type RuntimeImage struct {
    Python36RuntimeUrl   string
    Python27RuntimeUrl   string
    NodeJS1022RuntimeUrl string
    NodeJS1218RuntimeUrl string
    Golang1RuntimeUrl    string
    Java8RuntimeUrl      string
    PhpRuntimeUrl        string
}

type CodeInfo struct {
    GroupName    string `json:"groupName" valid:"length(1|2000)~缺少参数groupName"`
    FunctionName string `json:"functionName" valid:"length(1|2000)~缺少参数functionName"`
    VersionName  string `json:"versionName" valid:"length(1|2000)~缺少参数versionName"`
    DownloadLink string `json:"downloadLink" valid:"-"`
    Code         string `json:"code" valid:"-"`
    Bucket       string `json:"bucket" valid:"-"`
    Object       string `json:"object" valid:"-"`
}

type LayerFileInfo struct {
    DownloadLink string `json:"downloadLink,omitempty" valid:"-"`
    Code         string `json:"code,omitempty" valid:"-"`
    Bucket       string `json:"bucket,omitempty" valid:"-"`
    Object       string `json:"object,omitempty" valid:"-"`
}

type UploadInfo struct {
    Code         string
    SourceBucket string
    TargetBucket string
    SourceObject string
    TargetObject string
    TargetPath   string
    Ak           string
    Sk           string
}

type CallMessage struct {
    GroupName    string
    FunctionName string
    VersionName  string
    Event        string
    Id           string
    Host         string
}

type Environment struct {
    Key   string `json:"key" valid:"-"`
    Value string `json:"value" valid:"-"`
}

type Rule struct {
    Type    string         `json:"type" valid:"-"`
    Traffic []OptionalRule `json:"traffic" valid:"-"`
}

type OptionalRule struct {
    VersionName   string `json:"versionName" valid:"-"`
    VersionWeight int    `json:"versionWeight" valid:"range(0|100)~流量比例范围是0-100"`
}

type VpcInfo struct {
    VpcId    string `json:"vpcId,omitempty" valid:"-"`
    SubnetId string `json:"subnetId,omitempty" valid:"-"`
}

type VpcConfig struct {
    Eth     string
    Cidr    string
    Gateway string
    Remote  string
    Mac     string
}

type UpdateModel struct {
    FuncInfo        *FuncInfo
    VersionInfo     *FuncVersion
    VpcUpdateStatus VpcUpdateStatus
    OldVcpInfo      *VpcInfo
}
